
#include "lcd12864.c"
#include "uart.c"

/**
 * 128x64
 *
 * 字符尺寸
 * 4x8 SPEED SCORE 箭头符号 数字
 * 16x16  网博
 * 8x16  pause  IT@ANY
 *
 */

/**
 * 取模使用 字宽10  字高8，  得到5x8的字模
 */
unsigned char speed_chars_2[][5] =
    {
        {0x00, 0x26, 0x49, 0x49, 0x32}, /*"S",0*/
        {0x00, 0x7F, 0x09, 0x09, 0x06}, /*"P",1*/
        {0x00, 0x7F, 0x49, 0x49, 0x41}, /*"E",2*/
        {0x00, 0x7F, 0x49, 0x49, 0x41}, /*"E",3*/
        {0x00, 0x7F, 0x41, 0x41, 0x3E}, /*"D",4*/
};

unsigned char speed_chars_1[] =
    {
        0x00, 0x26, 0x49, 0x49, 0x32, /*"S",0*/
        0x00, 0x7F, 0x09, 0x09, 0x06, /*"P",1*/
        0x00, 0x7F, 0x49, 0x49, 0x41, /*"E",2*/
        0x00, 0x7F, 0x49, 0x49, 0x41, /*"E",3*/
        0x00, 0x7F, 0x41, 0x41, 0x3E, /*"D",4*/
};

/**
 * 仿真环境可以把大数据存放到xdata区域
 * xdata指代外部扩展的存储区，protues可以配置模拟一个外部扩展存储区
 * 在下载到硬件的时候，由于硬件没有配置外部扩展存储，xdata数据需要配置到code中，需要优化数据量大小
 */
unsigned char xdata itany[] = {
    0x00, 0x00, 0x00, 0xF8, 0xF8, 0x00, 0x00, 0x00,
    0x00, 0x00, 0x00, 0x3F, 0x3F, 0x00, 0x00, 0x00, /*"I",0*/
    0x00, 0x08, 0x08, 0xF8, 0xF8, 0x08, 0x08, 0x00,
    0x00, 0x00, 0x00, 0x3F, 0x3F, 0x00, 0x00, 0x00, /*"T",1*/
    0xE0, 0x10, 0x88, 0x68, 0x28, 0xE8, 0xF0, 0x00,
    0x0F, 0x10, 0x27, 0x28, 0x27, 0x28, 0x07, 0x00, /*"@",2*/
    0x00, 0x00, 0xC0, 0x78, 0x78, 0xC0, 0x00, 0x00,
    0x20, 0x3E, 0x07, 0x02, 0x02, 0x07, 0x3C, 0x20, /*"A",3*/
    0x00, 0xF8, 0x70, 0xC0, 0x00, 0x00, 0xF8, 0x00,
    0x00, 0x3F, 0x00, 0x01, 0x07, 0x3C, 0x3F, 0x00, /*"N",4*/
    0x08, 0x38, 0xE0, 0x80, 0xC0, 0x70, 0x18, 0x00,
    0x00, 0x00, 0x00, 0x3F, 0x3F, 0x00, 0x00, 0x00, /*"Y",5*/
};

unsigned char xdata itany_ch[] = {
    0x00, 0xFC, 0xFC, 0x24, 0x64, 0x84, 0xE4, 0x34,
    0x44, 0xC4, 0x84, 0xF4, 0x14, 0xFC, 0xFC, 0x00,
    0x00, 0xFF, 0xFF, 0x10, 0x0C, 0x07, 0x0F, 0x14,
    0x18, 0x0E, 0x03, 0x0E, 0x48, 0x7F, 0x7F, 0x00, /*"网",0*/
    0x00, 0x40, 0xFE, 0xFE, 0x40, 0x08, 0xE8, 0x68,
    0x68, 0xFE, 0x68, 0x68, 0x6A, 0xE8, 0x08, 0x00,
    0x00, 0x00, 0x7F, 0x7F, 0x00, 0x08, 0x0B, 0x39,
    0x29, 0x0B, 0x49, 0x49, 0x7D, 0x0B, 0x08, 0x08, /*"博",1*/
};

void demo_display_speed_1()
{
    unsigned char i, j;
    unsigned char col = 0;
    for (i = 0; i < sizeof(speed_chars_2) / sizeof(speed_chars_2[0]); i++)
    {
        for (j = 0; j < sizeof(speed_chars_2[0]) / sizeof(speed_chars_2[0][0]); j++)
        {
            lcd_display_one_byte_in_page(1, col++, speed_chars_2[i][j]);
        }
    }
}

void demo_display_speed_2()
{
    unsigned char i;
    unsigned char col = 0;
    for (i = 0; i < sizeof(speed_chars_1) / sizeof(speed_chars_1[0]); i++)
    {
        lcd_display_one_byte_in_page(3, col++, speed_chars_1[i]);
    }
}

void demo_display_itany()
{
    // 占用第5、6页，写英文字符 8x16
    unsigned char i, j;
    unsigned char col = 0;

    for (i = 0; i < sizeof(itany) / sizeof(itany[0]); i += 16)
    {
        // 处理16个byte， 前面8个写入第一页，后面8个写入第二页
        for (j = 0; j < 8; j++)
        {
            lcd_display_one_byte_in_page(5, col + j, itany[i + j]);
            lcd_display_one_byte_in_page(6, col + j, itany[i + j + 8]);
        }
        col += 8;
    }
}

void demo_display_itany_ch()
{
    // 占用第3、4页，从64列开始写，写中文字符 16x16
    unsigned char i, j;
    unsigned char col = 64;

    for (i = 0; i < sizeof(itany_ch) / sizeof(itany_ch[0]); i += 32)
    {
        // 处理16个byte， 前面8个写入第一页，后面8个写入第二页
        for (j = 0; j < 16; j++)
        {
            lcd_display_one_byte_in_page(3, col + j, itany_ch[i + j]);
            lcd_display_one_byte_in_page(4, col + j, itany_ch[i + j + 16]);
        }
        col += 16;
    }
}

void main()
{
    uart_init();
    lcd_init();
    lcd_clear_screan();
    demo_display_speed_1();
    demo_display_speed_2();
    demo_display_itany();
    demo_display_itany_ch();
    lcd_display_bytes_in_page(7, 64, speed_chars_1,
                              sizeof(speed_chars_1) / sizeof(speed_chars_1[0]));

    lcd_display_words_in_page(0, 64, itany_ch,
                              sizeof(itany_ch) / sizeof(itany_ch[0]),
                              16, 16);
    lcd_display_words_in_page(5, 64, itany,
                              sizeof(itany) / sizeof(itany[0]),
                              8, 16);
    while (1)
    {
    }
}